package cn.edu.scau.dropship.ServiceImpl;

import cn.edu.scau.dropship.entity.Goods;
import cn.edu.scau.dropship.entity.GoodsExample;
import cn.edu.scau.dropship.mapper.GoodsMapper;
import cn.edu.scau.dropship.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public long countByExample(GoodsExample example) {
        return goodsMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(GoodsExample example) {
        return goodsMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return goodsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Goods record) {
        return goodsMapper.insert(record);
    }

    @Override
    public int insertSelective(Goods record) {
        return goodsMapper.insertSelective(record);
    }

    @Override
    public List<Goods> selectByExample(GoodsExample example) {
        return goodsMapper.selectByExample(example);
    }

    @Override
    public Goods selectByPrimaryKey(Integer id) {
        return goodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Goods record, GoodsExample example) {
        return goodsMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Goods record, GoodsExample example) {
        return goodsMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Goods record) {
        return goodsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Goods record) {
        return goodsMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Goods> selectByState(String state) {
        GoodsExample goodsExample=new GoodsExample();
        GoodsExample.Criteria criteria=goodsExample.createCriteria();
        criteria.andStateEqualTo(state);
        List<Goods> list=goodsMapper.selectByExample(goodsExample);
        return  list;
    }

    @Override
    public Goods selectByTitle(String title) {
        GoodsExample goodsExample=new GoodsExample();
        GoodsExample.Criteria criteria=goodsExample.createCriteria();
        criteria.andTitleEqualTo(title);
        List<Goods> list=goodsMapper.selectByExample(goodsExample);
        if(list.size()>0){
            return list.get(0);
        }
        return  null;
    }

    @Override
    public List<Goods> selectAllByBrandId(Integer brandId) {
        GoodsExample goodsExample=new GoodsExample();
        GoodsExample.Criteria criteria=goodsExample.createCriteria();
        criteria.andIdIsNotNull();
        List<Goods> list=goodsMapper.selectByExample(goodsExample);
        return list;
    }

    @Override
    public int uploadToStorehouse(Integer id) {
        goodsMapper.uploadToStorehouse(id);
        return 1;
    }

    @Override
    public int uploadToStore(Integer id) {
        goodsMapper.uploadToStore(id);
        return 1;
    }

    @Override
    public int goOffFromStore(Integer id) {
        goodsMapper.goOffFromStore(id );
        return 1;
    }

    @Override
    public int offstorehouse(Integer id) {
        goodsMapper.offstorehouse(id);
        return 1;
    }

    @Override
    public List<Goods> selectGoodsByCompanyID(Integer mvo_id) {
        return goodsMapper.selectGoodsByCompanyID(mvo_id);
    }
}
